package se.djupfeldt.oscar.logbook.console.commands;

import se.djupfeldt.oscar.logbook.database.DatabaseHandler;
import se.djupfeldt.oscar.logbook.database.DatabaseHandler.DB_RESULT;

public class Select extends Command {
    
    private static Select instance;
    
    public static Select getInstance() {
	if (instance == null)
	    instance = new Select();
	return instance;
    }

    @Override
    public String execute(String[] args) {
	DatabaseHandler db = DatabaseHandler.getInstance();

	String query = "";
	for (String q : args) {
	    query += q + " ";
	}
	
	DB_RESULT result = db.selectAndPrint(query.trim());
	switch (result) {
	case SELECT_OK:
	    return "Select query ok.";
	case SELECT_FAILED:
	default:
	    return "Select query failed.";
	}
    }

    public String help() {
	String ret = "Select\nselect <query>\n<query> should be entered as an SQL select query, without the initial select";
	
	return ret;
    }
}
